/**
 * Created by TANG on 2021/3/26.
 */
layui.config({base:'../../layui/dropdown/'})
    .use(['form','table','layedit', 'laydate' ], function() {
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , $ = layui.$

        var map = new BMapGL.Map('container');
        map.centerAndZoom(new BMapGL.Point(116.404, 39.928), 15);
        map.enableScrollWheelZoom(true);
        // 创建点标记

        var point = [];
        var marker = [];


        form.on('submit(formDemo)', function(data){
            $.ajax({
                url: config.gatewayUri+"/"+config.deviceServiceId+"/api/device/admin/getBackNearbyDeviceList",
                data:{devicenumber:$("#devicenumber").val(),devicename:$("#devicename").val(),venuesName:$("#venuesName").val(),address:$("#address").val()},
                type: "get",
                dataType:"json",
                success:function(res){
                    if(res.data.length > 0){
                        point = [];
                        marker = [];
                        for(var i = 0;i<res.data.length;i++){
                            point[i] = new BMapGL.Point(res.data[i].longitude,res.data[i].latitude);
                            marker[i] = new BMapGL.Marker(point[i]);
                            if(i == 0){
                                map.centerAndZoom(point[i], 15);
                                map.enableScrollWheelZoom(true);
                            }
                            map.addOverlay(marker[i]);
                            createTag(marker[i],res.data[i]);
                        }
                    }else{
                        layer.msg("没有查询到相关设备!");
                    }
                }
            })
        });


        function createTag(marker,m){
            //标注
            var text = "<p>设备编号：" + m.devicenumber + "</p><p>设备名称：" + m.devicename
                + "</p><p>场地名称：" + m.venuesName + "</p><p>设备地址:"+ m.address+"</p>";

            var infoWindow = new BMapGL.InfoWindow("<p style='font-size:14px;'>" + text + "</p>");
            marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); });
        }

    })